package cn.tedu.zuoye.config;


import cn.tedu.zuoye.common.exception.BusinessException;
import cn.tedu.zuoye.response.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 功能描述: 针对controller层抛出的异常拦截统一处理
 */
@RestControllerAdvice(basePackages = {"cn.tedu.zuoye.controller"})
@Slf4j
public class GlobalControllerException {
    /**
     * 功能描述: controller层的APIException被捕获统一返回
     */
    @ExceptionHandler(BusinessException.class)
    public ResultVo APIExceptionHandler(BusinessException e) {
        log.error(e.getMessage(), e);
        return new ResultVo(e.getCode(), e.getMessage());
    }

}
